﻿using AutoMapper;
using FC.ERP.TMom.Api.AppHandlers.Commands.EssentialDatas.FactoryManages.WorkShops;
using FC.ERP.TMom.Domain;
using FC.ERP.TMom.ErrorCode;
using FC.ERP.TMom.Infrastructure.Interfaces;
using MediatR;

namespace FC.ERP.TMom.Api.AppHandlers.CommandHandlers.EssentialDatas.FactoryManages.WorkShops
{
    public class WorkShopUpdateCommandHandler : IRequestHandler<WorkShopUpdateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<WorkShop> workShoprepository;
        private readonly IMapper mapper;
        public WorkShopUpdateCommandHandler(IBaseRepository<WorkShop> workShoprepository, IMapper mapper)
        {
            this.workShoprepository = workShoprepository;
            this.mapper = mapper;
        }

        public async Task<APIResult<int>> Handle(WorkShopUpdateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            result.Code=ResultCode.更新成功;
            result.Message=ResultCode.更新成功.ToString();
            var entity = mapper.Map<WorkShop>(request);
            await workShoprepository.Update(entity);

            return await Task.FromResult(result);
        }
    }
}
